<template>
  <!--楼层-->
  <div class="swiper mySwiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="carousel in list" :key="carousel.id">
      <!-- <div class="swiper-slide" > -->
        <img :src="carousel.imgUrl" />
      </div>
    </div>
    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-next"></div>
    <div class="swiper-button-prev"></div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>
  </div>
</template>

<script>
// import { mapState } from "vuex";
export default {
  name: "Carousel",
  props: ["list"],
  mounted(){
    // console.log('Carousel组件',this.list)
  },

  // 为了提取为一个组件 所以这个样式和banner一样
  watch: {
    list: {
      immediate: true, // 页面一上来就监听一次
      handler() {
        this.$nextTick(() => {
          new Swiper(".mySwiper", {
            slidesPerView: 1,
            spaceBetween: 30,
            autoplay: true,
            loop: true,
            pagination: {
              el: ".swiper-pagination",
              clickable: true // 小圆点可以被点击
            },
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev"
            }
          });
        });
      }
    }
  }
};
</script>

<style scoped lang="less">

</style>
